Imports System
Imports System.Collections
Imports System.Text
Imports System.Xml
Imports DotNetNuke.Common.Utilities

Namespace DotNetNuke.Modules.ProjectTracker

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    '''		The StateSubscribersController class provides business layer methods
    '''		for StateSubscribers objects used by the Modules module.
    ''' </summary>
    ''' <remarks></remarks>
    ''' <history>
    '''		[MyGeneration]	7/3/2006 1:48:51 PM	Code file automatically generated from DotNetNuke.dnn_PT_StateSubscribers by MyGeneration v1.1.5.1
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Class StateSubscribersController

        Implements Entities.Modules.IPortable


        Public Sub New()
            ' default object initialisation	
        End Sub

#Region " Public Methods "

        ''' <summary>
        ''' Adds a new StateSubscribers record
        ''' </summary>
        ''' <returns>Identifier for the newly created object</returns>
        Public Function AddStateSubscribers(ByVal stateSubscribersInfo As StateSubscribersInfo) As Integer
            Return CType(DataProvider.Instance().AddStateSubscribers(stateSubscribersInfo.ModuleID, stateSubscribersInfo.CreatedByUser, stateSubscribersInfo.CreatedDate, stateSubscribersInfo.EMail, stateSubscribersInfo.StateID, stateSubscribersInfo.SubscriptionType), Integer)
        End Function


        ''' <summary>
        ''' Updates a specified StateSubscribers
        ''' </summary>
        ''' <returns></returns>
        Public Shared Sub UpdateStateSubscribers(ByVal stateSubscribersInfo As StateSubscribersInfo)
            DataProvider.Instance().UpdateStateSubscribers(stateSubscribersInfo.ItemID, stateSubscribersInfo.ModuleID, stateSubscribersInfo.CreatedByUser, stateSubscribersInfo.CreatedDate, stateSubscribersInfo.EMail, stateSubscribersInfo.StateID, stateSubscribersInfo.SubscriptionType)
        End Sub


        ''' <summary>
        ''' Deletes a specified StateSubscribers
        ''' </summary>
        ''' <returns></returns>
        Public Shared Sub DeleteStateSubscribers(ByVal itemID As Integer)
            DataProvider.Instance().DeleteStateSubscribers(itemID)
        End Sub


        ''' <summary>
        ''' Retrieves the details of a specified StateSubscribers
        ''' </summary>
        ''' <returns>StateSubscribersInfo object</returns>
        Public Function GetStateSubscribersInfo(ByVal itemID As Integer) As StateSubscribersInfo
            Return CType(CBO.FillObject(DataProvider.Instance().GetStateSubscribersInfo(itemID), GetType(StateSubscribersInfo)), StateSubscribersInfo)
        End Function


        ''' <summary>
        ''' Retrieves the entire list of StateSubscribersList
        ''' </summary>
        ''' <returns>ArrayList of StateSubscribersInfo objects</returns>
        Public Function GetStateSubscribersList(ByVal stateID As Integer, ByVal typeID As Integer) As ArrayList
            Return CBO.FillCollection(DataProvider.Instance().GetStateSubscribersList(stateID, typeID), GetType(StateSubscribersInfo))
        End Function


#End Region

#Region "Optional Interfaces"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' ExportModule implements the IPortable ExportModule Interface
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <param name="ModuleID">The Id of the module to be exported</param>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Function ExportModule(ByVal ModuleID As Integer) As String Implements Entities.Modules.IPortable.ExportModule
            Dim strXML As New StringBuilder

            strXML.Append("<statesubscriberslist>")

            Dim arrList As ArrayList = Me.GetStateSubscribersList(ModuleID, 1)
            If arrList.Count <> 0 Then
                For Each objItem As StateSubscribersInfo In arrList
                    strXML.Append("<statesubscribers>")
                    strXML.Append("<itemid>XMLEncode(objItem.ItemID.ToString())</itemid>")
                    strXML.Append("<moduleid>XMLEncode(objItem.ModuleID.ToString())</moduleid>")
                    strXML.Append("<createdbyuser>XMLEncode(objItem.CreatedByUser.ToString())</createdbyuser>")
                    strXML.Append("<createddate>XMLEncode(objItem.CreatedDate.ToString())</createddate>")
                    strXML.Append("<email>XMLEncode(objItem.EMail.ToString())</email>")
                    strXML.Append("<stateid>XMLEncode(objItem.StateID.ToString())</stateid>")
                    strXML.Append("<subscriptiontype>XMLEncode(objItem.SubscriptionType.ToString())</subscriptiontype>")
                    strXML.Append("</statesubscribers>")
                Next
            End If

            arrList = Me.GetStateSubscribersList(ModuleID, 2)
            If arrList.Count <> 0 Then
                For Each objItem As StateSubscribersInfo In arrList
                    strXML.Append("<statesubscribers>")
                    strXML.Append("<itemid>XMLEncode(objItem.ItemID.ToString())</itemid>")
                    strXML.Append("<moduleid>XMLEncode(objItem.ModuleID.ToString())</moduleid>")
                    strXML.Append("<createdbyuser>XMLEncode(objItem.CreatedByUser.ToString())</createdbyuser>")
                    strXML.Append("<createddate>XMLEncode(objItem.CreatedDate.ToString())</createddate>")
                    strXML.Append("<email>XMLEncode(objItem.EMail.ToString())</email>")
                    strXML.Append("<stateid>XMLEncode(objItem.StateID.ToString())</stateid>")
                    strXML.Append("<subscriptiontype>XMLEncode(objItem.SubscriptionType.ToString())</subscriptiontype>")
                    strXML.Append("</statesubscribers>")
                Next
            End If

            strXML.Append("</statesubscriberslist>")

            Return strXML.ToString()

        End Function

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' ImportModule implements the IPortable ImportModule Interface
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <param name="ModuleID">The Id of the module to be imported</param>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserId As Integer) Implements Entities.Modules.IPortable.ImportModule
            Dim xmlList As XmlNode = GetContent(Content, "statesubscriberslist")
            For Each xmlItem As XmlNode In xmlList.SelectNodes("statesubscribers")
                Dim objItem As New StateSubscribersInfo
                objItem.ItemID = CType(Null.GetNull(xmlItem.Item("itemid").InnerText, Null.NullInteger), Integer)
                objItem.ModuleID = CType(Null.GetNull(xmlItem.Item("moduleid").InnerText, Null.NullInteger), Integer)
                objItem.CreatedByUser = CType(Null.GetNull(xmlItem.Item("createdbyuser").InnerText, Null.NullInteger), Integer)
                objItem.CreatedDate = CType(Null.GetNull(xmlItem.Item("createddate").InnerText, Null.NullDate), DateTime)
                objItem.EMail = CType(Null.GetNull(xmlItem.Item("email").InnerText, Null.NullString), String)
                objItem.StateID = CType(Null.GetNull(xmlItem.Item("stateid").InnerText, Null.NullInteger), Integer)
                objItem.SubscriptionType = CType(Null.GetNull(xmlItem.Item("subscriptiontype").InnerText, Null.NullInteger), Integer)

                If objItem.ItemID = Null.NullInteger Then
                    Me.AddStateSubscribers(objItem)
                Else
                    Me.UpdateStateSubscribers(objItem)
                End If
            Next
        End Sub

#End Region


    End Class

End Namespace
